from openerp.osv import fields,osv

class res_partner(osv.osv):
    _inherit = 'res.partner'
    
    def _sale_order_count(self, cr , uid, ids , fields, arg, context=None):
        res = dict(map(lambda x:(0,x), ids)
        # the current user may not have access right for sale orders
        try:
            for partner in self.browse(cr, uid, ids, context):
                res[partner.id] = len(partner.sale_order_ids)
            except:
                pass
            return res
        
        _columns = {
            'sale_order_count' = fields.function(_sale_order_count, string = '# of sale order' , type='integer'),
            'sale_order_ids':fields.one2many('sale.order','partner_id','Sale Order')
        }
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        